// demo_transform.js

const { Transform } = require('stream');

const upperCaseTr = new Transform({
    transform(chunk, encoding, callback) {
        this.push(chunk.toString().toUpperCase());
        callback();
    }
});

const stdout = process.stdout;
// stdout.on('close', () => {});

const stdin = process.stdin;
stdin.on('data', (chunk) => {
    console.log(`-> ${chunk.toString()}, length: ${chunk.toString().length}`);
    console.log(`-> ${chunk.toString().indexOf('\n')}`)
    if(chunk && ( chunk.toString() === '\r\n' || chunk.toString() === '\n' )) {
        // console.log(`-> this: ${JSON.stringify(stdin)}`);
        // this.push(null);
        process.exit(0);
    }
});

stdin.pipe(upperCaseTr).pipe(stdout);


